package org.example.rocket;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeOrderlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerOrderly;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class ConsumerPrint {
    public static void main(String[] args) {
        try {
            DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("groupC");
            consumer.setNamesrvAddr("localhost:9876");
            consumer.registerMessageListener(new MsgHandler2());
            consumer.subscribe("JieGuo","*");


            System.out.println("开始监听故障诊断结果");
            consumer.start();
        }catch (Exception e){
            e.printStackTrace();
        }

    }


    static class MsgHandler2 implements MessageListenerOrderly {

        @Override
        public ConsumeOrderlyStatus consumeMessage(List<MessageExt> list, ConsumeOrderlyContext consumeOrderlyContext) {
            list.forEach(l->{
                String string = new String(l.getBody());
                System.err.println("获取到了故障诊断结果："+string);
            });
            return ConsumeOrderlyStatus.SUCCESS;
        }
    }
}
